<template>
    <div>
        <a-modal v-model:visible="modalVisible" title="操作记录" @ok="handleOk">
            <a-table :dataSource="dataSource">
                <a-table-column key="created_at" title="操作时间" data-index="created_at" />
                <a-table-column key="action" title="操作内容" data-index="action">
                    <template #default="{ record }">
                        <span v-if="record.subject == 'schedule_stop'">
                            <span v-if="record.action == 'setting'">设置定时关机</span>
                            <span v-if="record.action == 'stop'">定时关机</span>
                        </span>
                        <span v-else>{{ selectDictLabel(instanceLogEnum, (record.subject ? record.subject : record.action)) }}</span>
                    </template>
                </a-table-column>
            </a-table>

        </a-modal>
    </div>
</template>

<script setup>
import { defineProps, defineEmits, computed, ref } from 'vue';
import { getActionlist } from 'api/modules/api.instance'
import { selectDictLabel, instanceLogEnum } from '../enum.js'

const props = defineProps({
    modelValue: {
        type: Boolean,
    },
    instance: {
        type: Object,
        default: {}
    },
});


const emit = defineEmits(['update:modelValue']);
const modalVisible = computed({
    get: () => props.modelValue,
    set: v => emit('update:modelValue', v),
});
// 确定按钮的回调
const handleOk = () => {
    emit('update:modelValue', false)
};

const getList = () => {
    const params = {
        instanceId: props.instance?.Instance?.instanceId,
    }

    getActionlist(params).then(res => {
        dataSource.value = res.data.list
    })
}

getList()

const dataSource = ref([])

</script>

